package com.exp.bookhouse.service.impl;

import com.exp.bookhouse.pojo.vo.ShopCartInfo;
import com.exp.bookhouse.service.ShopCartService;
import com.exp.bookhouse.util.ConstUtils;
import com.exp.bookhouse.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@PropertySource(value = "classpath:message.properties")
@Service
@Transactional
public class ShopCartServiceImpl implements ShopCartService {

    @Autowired
    private RedisUtil redisUtil;

    @Value("${redis.cartName}")
    private String cartName;    //购物车key的名字

    /**
     * 查询购物车信息
     * @return
     */
    @Override
    public Object queryShopCart(Long id) {
        return redisUtil.get(ConstUtils.CART + id);
    }

    /**
     * 缓存购物车信息 3天
     * @param shopCartInfo
     */
    @Override
    public boolean saveShopCart(ShopCartInfo shopCartInfo) {
        return redisUtil.set(ConstUtils.CART + shopCartInfo.getUid(),shopCartInfo,60 * 60 * 24 * 3);
    }
}
